package parser

import (
	"bytes"
	"luiz/crawler/engine"
	"luiz/crawler_distributed/config"
	"regexp"
)

const arealist = `<div class="wrapper">[\s\S]*?</div>`
const areaurl = `<a class="item " href="//([^"]+)">([^<]+)`

func PreaseArea(contents []byte, _ string) engine.ParseResult {
	compile := regexp.MustCompile(arealist)
	areadiv := compile.FindString(string(contents))
	compile = regexp.MustCompile(areaurl)
	areadeatil := compile.FindAllStringSubmatch(areadiv, -1)
	result := engine.ParseResult{}
	for _, ele := range areadeatil {
		var bt bytes.Buffer
		bt.WriteString("http://")
		bt.WriteString(ele[1])
		//ParserFunc: PreaseUrls
		result.Request = append(result.Request, engine.Request{Url: bt.String(), Parser: engine.NewFuncParser(PreaseUrls, config.PreaseUrls)})
		//fmt.Printf("%v %v\n", ele[1], "区域："+ele[2])
	}
	return result
}
